package com.algorithm;

/**
 * @author: sun.hongliang
 * @create: 2019/12/10 15:11
 */
public class PlusOneTest {


    public int[] plusOne(int[] digits) {
        int len = digits.length;
        int d = 1;
        for (int i = len - 1; i >= 0; i--) {
            int temp = digits[i] + d;
            if (temp < 10) {
                digits[i] = temp;
                return digits;
            } else {
                digits[i] = 0;
            }
        }
        int[] res = new int[len + 1];
        res[0] = 1;
        return res;
    }
}
